package cn.gson.fengboot.controller;
import cn.gson.fengboot.model.pojos.Ltousu;
import cn.gson.fengboot.model.service.LtousuService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/vue")
public class LtousuController {
    @Autowired
    LtousuService ltousuService;


    //查询所有客户的投诉
    @RequestMapping("/khtousu")
    @ResponseBody
    public Map<String,Object> khtousu(Integer currentPage , Integer pageSize,String search,String fenlei){
        if(currentPage==null || currentPage==' '||pageSize==null||pageSize==' '){
            currentPage=1;
            pageSize=5;
        }
        Page<Object> obj= PageHelper. startPage(  currentPage, pageSize);
        List<Ltousu> ltousu = ltousuService.khtousu(search,fenlei);
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("row",ltousu);
        return map;
    }

    //新增客户的投诉信息
    @RequestMapping("/addkhtousu")
    @ResponseBody
    public  void addkhtousu(@RequestBody Ltousu ltousu ){
         ltousuService.addkhtousu(ltousu);
    }

    //
    @RequestMapping("/tousulx")
    @ResponseBody
    public Map<String ,Object> tousulx(String lxname){
        Map<String,Object> map= null;
        if (lxname.equals("投诉类型分布")){
            map= ltousuService.tousulx();
        }else if (lxname.equals("投诉花费时间分布")){
            map= ltousuService.hfsj();
        }
        return map;
    }


    @RequestMapping("/ydtsfb")
    @ResponseBody
    public Map<String ,Object> ydtsfb(String ydtsfb){
        Map<String,Object> map= null;
        if (ydtsfb.equals("投诉月度统计")){
            map= ltousuService.ydtsfb();
        }
        else if (ydtsfb.equals("客户投诉次数top10")){
            map= ltousuService.khtsfb();
        }
        return map;
    }


    @RequestMapping("/ydjjcdfb")
    @ResponseBody
    public Map<String ,Object> ydjjcdfb(String ydjjcdfb){
        Map<String,Object> map= ltousuService.zhexian();
        if (ydjjcdfb.equals("投诉月度紧急程度统计")){
            map= ltousuService.zhexian();
        }
        else if (ydjjcdfb.equals("投诉月度/解决状态统计")){
            map=ltousuService.zhexian1();
        }
        return map;
    }



}
